package cn.virens.dd.execute;

import java.util.ArrayList;
import java.util.List;

import cn.virens.common.fun.ExConsumer;
import cn.virens.common.fun.ExFunction;

public class ExecuteResult extends ArrayList<Exception> {
	private static final long serialVersionUID = -7811678702073378582L;

	public static final ExecuteResult EMPTY = new ExecuteResult();

	public <T> boolean execute(T obj, ExConsumer<T> con) {
		try {
			con.accept(obj);
		} catch (Exception e) {
			return add(e);
		}

		return false;
	}

	public <T> boolean execute(T obj, ExFunction<T, List<Exception>> fun) {
		try {
			return addAll(fun.apply(obj));
		} catch (Exception e) {
			return add(e);
		}
	}
}
